import _Checkbox from "choerodon-ui/lib/checkbox";
import _InputNumber from "choerodon-ui/lib/input-number";
import _List from "choerodon-ui/lib/list";
import _Output from "choerodon-ui/pro/lib/output";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _Select from "choerodon-ui/lib/select";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _Radio from "choerodon-ui/lib/radio";
import React, { PureComponent } from 'react';
import styles from "./index.less?modules";
var Group = _Radio.Group;

var Week = /*#__PURE__*/function (_PureComponent) {
  _inherits(Week, _PureComponent);

  var _super = _createSuper(Week);

  function Week() {
    var _this;

    _classCallCheck(this, Week);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));
    _this.weekOptions = [{
      label: '星期一',
      value: '1'
    }, {
      label: '星期二',
      value: '2'
    }, {
      label: '星期三',
      value: '3'
    }, {
      label: '星期四',
      value: '4'
    }, {
      label: '星期五',
      value: '5'
    }, {
      label: '星期六',
      value: '6'
    }, {
      label: '星期日',
      value: '7'
    }];
    return _this;
  }

  _createClass(Week, [{
    key: "getWeekOptions",
    value: function getWeekOptions() {
      return this.weekOptions.map(function (item) {
        return /*#__PURE__*/React.createElement(_Select.Option, {
          value: item.value,
          key: item.value
        }, item.label);
      });
    }
  }, {
    key: "changeParams",
    value: function changeParams(type, value) {
      var state = _objectSpread({}, this.props.week);

      state[type] = value;
      this.props.onChange(state);
    }
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;

      var _this$props$week = this.props.week,
          type = _this$props$week.type,
          start = _this$props$week.start,
          end = _this$props$week.end,
          some = _this$props$week.some,
          begin = _this$props$week.begin,
          beginEvery = _this$props$week.beginEvery,
          last = _this$props$week.last;
      return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Group, {
        value: type,
        onChange: function onChange(e) {
          var state = _objectSpread({}, _this2.props.week);

          if (e.target.value === 'some') {
            state.some = ['1'];
          }

          if (e.target.value === 'beginInterval') {
            state.begin = 1;
          }

          state.type = e.target.value;

          _this2.props.onChange(state);
        }
      }, /*#__PURE__*/React.createElement(_List, {
        size: "small",
        bordered: true,
        className: styles['cron-list']
      }, /*#__PURE__*/React.createElement(_List.Item, null, /*#__PURE__*/React.createElement(_Radio, {
        value: "*"
      }), /*#__PURE__*/React.createElement(_Output, {
        value: "\u6BCF\u5468"
      })), /*#__PURE__*/React.createElement(_List.Item, null, /*#__PURE__*/React.createElement(_Radio, {
        value: "?"
      }), /*#__PURE__*/React.createElement(_Output, {
        value: "\u4E0D\u6307\u5B9A"
      })), /*#__PURE__*/React.createElement(_List.Item, {
        style: {
          marginBottom: 5
        }
      }, /*#__PURE__*/React.createElement(_Radio, {
        value: "period"
      }), /*#__PURE__*/React.createElement(_Output, {
        value: "\u5468\u671F"
      }), /*#__PURE__*/React.createElement(_Output, {
        value: "\u4ECE\xA0"
      }), /*#__PURE__*/React.createElement(_Select, {
        style: {
          width: 100
        },
        defaultValue: "1",
        placeholder: "\u5468" // size="small"
        ,
        value: start,
        onChange: function onChange(value) {
          _this2.changeParams('start', value);
        } // 滚动区域的scrollArea由调用方设置id="scrollArea"，不设置默认滚动区域为document.body
        ,
        getPopupContainer: function getPopupContainer() {
          return document.getElementById('scrollArea') || document.body;
        }
      }, this.getWeekOptions()), /*#__PURE__*/React.createElement(_Output, {
        value: "\xA0\u5230\xA0"
      }), /*#__PURE__*/React.createElement(_Select, {
        style: {
          width: 100
        },
        defaultValue: "2",
        placeholder: "\u5468",
        value: end // size="small"
        ,
        onChange: function onChange(value) {
          _this2.changeParams('end', value);
        },
        getPopupContainer: function getPopupContainer() {
          return document.getElementById('scrollArea') || document.body;
        }
      }, this.getWeekOptions())), /*#__PURE__*/React.createElement(_List.Item, null, /*#__PURE__*/React.createElement(_Radio, {
        value: "beginInterval"
      }), /*#__PURE__*/React.createElement(_Output, {
        value: "\u7B2C\xA0"
      }), /*#__PURE__*/React.createElement(_InputNumber, {
        style: {
          width: 120
        },
        min: 1,
        defaultValue: 1,
        placeholder: "\u5468",
        size: "small",
        value: begin,
        onChange: function onChange(value) {
          _this2.changeParams('begin', value);
        }
      }), /*#__PURE__*/React.createElement(_Output, {
        value: "\xA0\u5468\u7684\xA0"
      }), /*#__PURE__*/React.createElement(_Select, {
        style: {
          width: 100
        },
        defaultValue: "1",
        placeholder: "\u661F\u671F",
        value: beginEvery // size="small"
        ,
        onChange: function onChange(value) {
          _this2.changeParams('beginEvery', value);
        },
        getPopupContainer: function getPopupContainer() {
          return document.getElementById('scrollArea') || document.body;
        }
      }, this.getWeekOptions())), /*#__PURE__*/React.createElement(_List.Item, {
        style: {
          marginBottom: 5
        }
      }, /*#__PURE__*/React.createElement(_Radio, {
        value: "last"
      }), /*#__PURE__*/React.createElement(_Output, {
        value: "\u672C\u6708\u6700\u540E\u4E00\u4E2A\xA0"
      }), /*#__PURE__*/React.createElement(_Select, {
        style: {
          width: 100
        },
        defaultValue: 1,
        placeholder: "\u661F\u671F" // size="small"
        ,
        value: last,
        onChange: function onChange(value) {
          _this2.changeParams('last', value);
        },
        getPopupContainer: function getPopupContainer() {
          return document.getElementById('scrollArea') || document.body;
        }
      }, this.getWeekOptions())), /*#__PURE__*/React.createElement(_List.Item, null, /*#__PURE__*/React.createElement(_Radio, {
        value: "some"
      }), /*#__PURE__*/React.createElement(_Output, {
        value: "\u6307\u5B9A\xA0"
      }), /*#__PURE__*/React.createElement(_Checkbox.Group, {
        value: some,
        defaultValue: ['1'],
        onChange: function onChange(value) {
          _this2.changeParams('some', value);
        },
        options: this.weekOptions
      })))));
    }
  }]);

  return Week;
}(PureComponent);

export { Week as default };